//
//  UIImageAddational.m
//  OGL
//
//  Created by ZengYuan on 14/12/17.
//  Copyright (c) 2014年 ZengYuan. All rights reserved.
//

#import "UIImageAddational.h"
#import "Config.h"
@implementation UIImage(Addational)
-(UIImage *)adaptiveImageNamed:(NSString *)name{
    return  [UIImage imageNamed:name];
}


+(UIImage *)imageRedraw:(UIImage *)_image{
    
    NSLog(@"w=%.2f, h=%.2f", _image.size.width,_image.size.height);
    
    if (_image.size.height < 640 && _image.size.width < 640) {
        return _image;
    }
    
    
    CGRect rect;
    float scale=_image.size.width/_image.size.height;
    
    //横屏
    if (scale > 1) {
        rect=CGRectMake(0, 0, 640, 640/scale);
        
    }else{
        rect=CGRectMake(0, 0,  640*scale, 640);
    }
    
    UIGraphicsBeginImageContext(CGSizeMake(rect.size.width,rect.size.height));
    [_image drawInRect:rect];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return newImage;
}

@end
